#include <iostream>
#include <vector>
#include "myThread.hpp"
using namespace ThreadMoudle;

// 抢票
int tickets = 10000; // 票

void *threadRun(std::string &name)
{
    while (true)
    {
        if (tickets > 0)
        {
            usleep(1000);//单位 微秒
            std::cout << name << " ticket " << tickets << std::endl;
            tickets--;
        }
        else
        {
            break;
        }
    }

    return (void *)111;
}
int main()
{
    myThread t1("thread-1", threadRun);
    myThread t2("thread-2", threadRun);
    myThread t3("thread-3", threadRun);
    myThread t4("thread-4", threadRun);
    t1.Start(); // 运行
    t2.Start();
    t3.Start();
    t4.Start();

    t1.Join(); // 等待
    t2.Join();
    t3.Join();
    t4.Join();

    return 0;
}

// void* threadRun(std::string& name)
// {
//     return (void*)111;
// }
// int main()
// {
//     std::string name = "thread-1";
//     myThread mythread(name, threadRun);
//     mythread.Start();//运行
//     std::cout << mythread.Name() << " " << mythread.Stat() << std::endl;
//     mythread.Stop();
//     mythread.Join();//等待

//     return 0;
// }